package mysql

import (
	"database/sql"
	f "fmt"

	_ "github.com/go-sql-driver/mysql"
)

// sql.Open里是username：password@protocol(port)/database name
func InsertData(id int, finish int, money int) {
	DB, err := sql.Open("mysql", "root:123456@tcp(db)/beego?charset=utf8mb4&parseTime=true&loc=Local")
	//验证连接
	if err != nil {
		f.Println(err.Error())
		return
	}
	f.Print("db connect success")
	defer DB.Close()

	err = DB.Ping()
	if err != nil {
		f.Println("big erro")
		panic(err.Error())
	}

	//insert 到mysql
	insert, err := DB.Query("insert into `go_project`.`id`(`id`, `finish`,`money`) values(" +
		string(id) + "," + string(finish) + "," + string(money) + ")")
	if err != nil {
		panic(err.Error())
	}
	defer insert.Close()
	f.Println("INSERT SUCCESS")
}
